home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MEMORY.SWG / 0001_BIGMEM1.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  50 lines

  1. > I have seen posts about using Pointer Arrays instead of the standard fixed
  2. > Arrays.  These posts have been helpful but I think the rewriting of an example
  3. > problem would benefit me the best.  Please take a look at this simple example
  4. > code:
  5. >
  6. > Program LotsofData;
  7. >
  8. > Type LOData = Array [1..10000] of Real;
  9. >
  10. > Var Value : LOData;
  11. >     MaxSizeArray, I, NumElement : Integer;
  12. >     NewValue : Real;
  13. >
  14. > begin
  15. >   Write('Please input the Maximum Size of the Array: ');
  16. >   Readln(MaxSizeArray);
  17. >   For I := 1 to MaxSizeArray Do
  18. >     Value[I] := 0.0;
  19. >   Writeln('Array Initialized');
  20. >   Writeln;
  21. >   Write('Please input the Number of Array Element to Change: ');
  22. >   Readln(NumElement);
  23. >   Write('Please input the New Number For Value[',NumElement,']: ');
  24. >   Readln(NewValue);
  25. >   Value[NumElement] := NewValue;
  26. > end.
  27. >
  28.  
  29. Response;
  30. 1. Declare the Variable Value as LOData -
  31.         e.g. Var Value : LOData;
  32.  
  33. 2. Read MaxSizeArray;
  34.  
  35. 3. Allocate memory For the Array by using NEW() or GETMEM()
  36.          e.g. NEW(Value);
  37.         or   GetMem(Value, Sizeof(Real) * MaxSizeArray);
  38.  
  39. Getmem() is better because you can allocate just the precise amount of
  40. memory needed.
  41.  
  42. 4. From then on refer to your Array as Value
  43.         e.g. Value[Element] := NewValue;
  44.  
  45. 5. When you finish, deallocate memory by
  46.         [a] Dispose(Value) - if you used NEW() to begin with, or
  47.         [b] FreeMem(Value, Sizeof(Real) * MaxSizeArray) - if you used
  48.         GetMem() to begin with.
  49.  
  50.